<?
	////
	///
	//	String
			function JO_string_textArray( $text, $assign = ":", $separate = ";" ) {	/// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// ///
			if( ! $text ) return null;
			if( strpos( $text, $separate ) == false && strpos( $text, $assign ) == false ) return array( trim( $text ) );
			$sentence = explode( $separate, $text );
			foreach( $sentence as $key => $value ) {
				if( ! $value ) continue;
				if( strpos( $value, $assign ) == false ) {
					$result[ $key ] = trim( $value );
				} else {
					$word = explode( $assign, $value );
					if( $word[ 0 ] ) $result[ trim( $word[ 0 ] ) ] = trim( $word[ 1 ] );
				}
			}
			return $result;
		} function JO_textArray( $text, $assign = ":", $separate = ";" ) { return JO_string_textArray( $text, $assign, $separate ); }
		function JO_string_date( $date, $class = "JO_gray_40" ) {	/// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// ///
			global $JO_language;
			switch( $JO_language ) {
				case "EN":	return substr( $date, 5, 2 ) . "<span class='" . $class . "'>/</span>" . substr( $date, 8, 2 ) . "<span class='" . $class . "'>/</span>" . substr( $date, 0, 4 );
				case "KO":	return substr( $date, 0, 4 ) . "<span class='" . $class . "'>-</span>" . substr( $date, 5, 2 ) . "<span class='" . $class . "'>-</span>" . substr( $date, 8, 2 );
				case "VI":	return substr( $date, 8, 2 ) . "<span class='" . $class . "'>/</span>" . substr( $date, 5, 2 ) . "<span class='" . $class . "'>/</span>" . substr( $date, 0, 4 );
				default:	return substr( $date, 0, 4 ) . "<span class='" . $class . "'>-</span>" . substr( $date, 5, 2 ) . "<span class='" . $class . "'>-</span>" . substr( $date, 8, 2 );
			}
		} function JO_date( $date, $class = "JO_gray_40" ) { return JO_string_date( $date, $class ); }
	////
	///
	//	JavaScript
		function JO_JS_location( $URL = false ) {	/// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// ///
			global $JO_MySQL;
			$JO_MySQL -> close( );
			if( $URL )	exit( "<script> try { parent.location.replace ( '" . $URL .		"'						); } catch ( exception ) { location.replace( '" . $URL . "'							); } </script>" );
			else		exit( "<script> try { parent.location.replace ( '" . $_SERVER[ "HTTP_REFERER" ] . "'	); } catch ( exception ) { location.replace( '" . $_SERVER[ "HTTP_REFERER" ] . "'	); } </script>" );
		} function JO_location( $URL = false ) { JO_JS_location( $URL ); }
		function JO_JS_innerHTM( $object, $content, $class = null ) {	/// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// ///
			if( $class )	echo "<script> parent.document.getElementById( '" . $object . "' ).setAttribute( 'class', '" . $class . "' );	</script>";
							echo "<script> parent.document.getElementById( '" . $object . "' ).innerHTML = \"" . $content . "\";			</script>";
		} function JO_innerHTM( $object, $content, $class = null ) { JO_JS_innerHTM( $object, $content, $class ); }
	////
	///
	//	Session
		function JO_session( ) {	/// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// ///
			$_SESSION[ $_REQUEST[ "JO_session_key" ] ] = $_REQUEST[ "JO_session_value" ];
			echo "<b>Asynchronous</b> : \$_SESSION[ '" . $_REQUEST[ "JO_session_key" ] . "' ] = '" . $_REQUEST[ "JO_session_value" ] . "';";
		}
	////
	///
	//	Database
		function JO_database_query( $query ) {	/// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// ///
			global $JO_MySQL;
			// JO_90_log_query
			return $JO_MySQL -> query( $query );
			// echo $mysqli -> error;
		} function JO_query( $query ) { return JO_database_query( $query ); }
	////
	///
	//	Language
		function JO_language( $value ) {	/// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// ///
			global $JO_language;
			$language = $JO_language;
			if( is_array( $value ) ) {
				return $value[ $language ];
			} else {
				if( strpos( $value, "{" . $language . "}" ) === false ) {
					if( strpos( $value, "{EN}" ) === false ) return $value;
					else									$language = "EN";
				}
				$temp = explode( "{"	. $language . "}", $value		);
				$temp = explode( "{/"	. $language . "}", $temp[ 1 ]	);
				return $temp[ 0 ];
			}
		} function JO( $array ) { return JO_language( $array ); }
	////
	///
	//	Account
		function JO_account( ) {	/// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// ///
			$status_identifier		= true;
			$status_password		= true;
			$status_confirmation	= true;
			$status_name			= true;
			$status_mail			= true;
			foreach( $_REQUEST as $key => $value ) $_REQUEST[ $key ] = trim( $value );
			////
			///
			//	Identifier
				if( $_REQUEST[ "JO_account_query" ] == "identifier" || $_REQUEST[ "JO_account_query" ] == "insert" || $_REQUEST[ "JO_account_query" ] == "update" ) {
					if(			empty(	$_REQUEST[ "JO_account_identifier" ] )		) { JO_innerHTM( "JO_account_identifier_guide", "The value of 'Identifier' is indispensable."				, "JO_absolute JO_negative" ); $status_identifier = false; }
					else if(	strlen(	$_REQUEST[ "JO_account_identifier" ] ) < 5	) { JO_innerHTM( "JO_account_identifier_guide", "The value of 'Identifier' might be minimum 5 characters."	, "JO_absolute JO_negative" ); $status_identifier = false; }
					else if(	strlen(	$_REQUEST[ "JO_account_identifier" ] ) > 16 ) { JO_innerHTM( "JO_account_identifier_guide", "The value of 'Identifier' might be maximum 16 characters."	, "JO_absolute JO_negative" ); $status_identifier = false; }
					if( isset($_REQUEST[ "JO_account_identifier" ]) != $_SESSION[ "JO_account_identifier" ] && $status_identifier ) {
						$query = "SELECT `key` FROM `account` WHERE `identifier` = '" . $_REQUEST[ "JO_account_identifier"	] . "'";
						$recordSet = JO_query( $query );
						if( $recordSet -> num_rows ) { JO_innerHTM( "JO_account_identifier_guide", "The value of 'Identifier' is being used by another user.", "JO_absolute JO_negative"  ); $status_identifier = false; }
					}
					if( $status_identifier ) JO_innerHTM( "JO_account_identifier_guide", "The value of 'Identifier' is available.", "JO_absolute JO_positive" );
				}
			////
			///
			//	Password
				if( $_REQUEST[ "JO_account_query" ] == "password" || $_REQUEST[ "JO_account_query" ] == "insert" || $_REQUEST[ "JO_account_query" ] == "update" ) {
					if(			empty(	$_REQUEST[ "JO_account_password" ] )		) { JO_innerHTM( "JO_account_password_guide", "The value of 'Password' is indispensable."				, "JO_absolute JO_negative" ); $status_password = false; }
					else if(	strlen( $_REQUEST[ "JO_account_password" ] ) < 5	) { JO_innerHTM( "JO_account_password_guide", "The value of 'Password' might be minimum 5 characters."	, "JO_absolute JO_negative" ); $status_password = false; }
					else if(	strlen( $_REQUEST[ "JO_account_password" ] ) > 16	) { JO_innerHTM( "JO_account_password_guide", "The value of 'Password' might be maximum 16 characters."	, "JO_absolute JO_negative" ); $status_password = false; }
					if( $status_password ) JO_innerHTM( "JO_account_password_guide", "The value of 'Password' is available.", "JO_absolute JO_positive" );
				}
			////
			///
			//	Password Confirmation
				if( $_REQUEST[ "JO_account_query" ] == "confirmation" || $_REQUEST[ "JO_account_query" ] == "insert" || $_REQUEST[ "JO_account_query" ] == "update" ) {
					if(	empty(	$_REQUEST[ "JO_account_confirmation" ] )										) { JO_innerHTM( "JO_account_confirmation_guide", "The value of 'Password Conmfirmation' is indispensable."								, "JO_absolute JO_negative"  ); $status_confirmation = false; }
					else if(	$_REQUEST[ "JO_account_confirmation" ] != $_REQUEST[ "JO_account_password" ]	) { JO_innerHTM( "JO_account_confirmation_guide", "The value of \'Password\' and the value of 'Password Confirmation' are different."	, "JO_absolute JO_negative"  ); $status_confirmation = false; }
					if( $status_confirmation ) JO_innerHTM( "JO_account_confirmation_guide", "The value of 'Password Confirmation' is available.", "JO_absolute JO_positive" );
				}
//quest
if( $_REQUEST[ "JO_account_query" ] == "JO_account_quest" || $_REQUEST[ "JO_account_query" ] == "insert" || $_REQUEST[ "JO_account_query" ] == "update" ) {
					$number_quest=Array(1, 2, 3,4,5);
					if($_REQUEST[ "JO_account_quest"]==""  &&	in_array($_REQUEST[ "JO_account_quest"] ,$number_quest) ) { JO_innerHTM( "JO_account_quest_guide", "The value of 'Secret Question' is indispensable."								, "JO_absolute JO_negative"  ); $status_quest = false; }
					else if(	$_REQUEST[ "JO_account_quest" ] != ""	) { JO_innerHTM( "JO_account_quest_guide", "The value of \'Secret Question\' is available."	, "JO_absolute JO_positive"  ); $status_quest = true; }
				}
				//anwser
if( $_REQUEST[ "JO_account_query" ] == "JO_account_answer" || $_REQUEST[ "JO_account_query" ] == "insert" || $_REQUEST[ "JO_account_query" ] == "update" ) {
					if($_REQUEST[ "JO_account_answer"]==""  &&	in_array($_REQUEST[ "JO_account_answer"] ,$number_quest) ) { JO_innerHTM( "JO_account_quest_guide", "The value of 'Secret Question' is indispensable."								, "JO_absolute JO_negative"  ); $status_ans = false; }
					else if(	strlen( $_REQUEST[ "JO_account_answer" ] ) < 5	) { JO_innerHTM( "JO_account_answer_guide", "The value of 'Secret Anwser' might be minimum 5 characters."	, "JO_absolute JO_negative" ); $status_ans = false; }
					else if(	$_REQUEST[ "JO_account_answer" ] != ""	) { JO_innerHTM( "JO_account_answer_guide", "The value of \'Secret Anwser\' is available."	, "JO_absolute JO_positive"  ); $status_ans = true; }
					}
			////
			///
			//	Name
				if( $_REQUEST[ "JO_account_query" ] == "name" || $_REQUEST[ "JO_account_query" ] == "insert" || $_REQUEST[ "JO_account_query" ] == "update" ) {
					if(			empty(	$_REQUEST[ "JO_account_name" ] )		) { JO_innerHTM( "JO_account_name_guide", "The value of 'Name' is indispensable."				, "JO_absolute JO_negative" ); $status_name = false; }
					else if(	strlen( $_REQUEST[ "JO_account_name" ] ) < 5	) { JO_innerHTM( "JO_account_name_guide", "The value of 'Name' might be minimum 5 characters."	, "JO_absolute JO_negative" ); $status_name = false; }
					else if(	strlen( $_REQUEST[ "JO_account_name" ] ) > 32	) { JO_innerHTM( "JO_account_name_guide", "The value of 'Name' might be maximum 16 characters."	, "JO_absolute JO_negative" ); $status_name = false; }
					if( $status_name ) JO_innerHTM( "JO_account_name_guide", "The value of 'Name' is available.", "JO_absolute JO_positive" );
				}
			////
			///
			//	Mail
				if( $_REQUEST[ "JO_account_query" ] == "mail" || $_REQUEST[ "JO_account_query" ] == "insert" || $_REQUEST[ "JO_account_query" ] == "update" ) {
					if( empty(	$_REQUEST[ "JO_account_mail" ] ) ) { JO_innerHTM( "JO_account_mail_guide", "The value of 'Mail' is indispensable.", "JO_absolute JO_negative" ); $status_mail = false; }
					// Validate.
					if( $status_mail ) JO_innerHTM( "JO_account_mail_guide", "The value of 'mail' is available.", "JO_absolute JO_positive" );
				}
			if( $status_identifier && $status_password && $status_confirmation && $status_name && $status_mail && $status_ans && $status_quest ) {
				if( $_REQUEST[ "JO_account_birth_year" ] && $_REQUEST[ "JO_account_birth_month" ] && $_REQUEST[ "JO_account_birth_day" ] ) 
				$_REQUEST[ "JO_account_birth" ] = $_REQUEST[ "JO_account_birth_year" ] . "-" . $_REQUEST[ "JO_account_birth_month" ] . "-" . $_REQUEST[ "JO_account_birth_day" ];
				////
				///
				//	Insert
					if( $_REQUEST[ "JO_account_query" ] == "insert" ) {
						$_REQUEST[ "JO_account_birth" ]='';
					if( $_REQUEST[ "JO_account_birth_year" ] && $_REQUEST[ "JO_account_birth_month" ] && $_REQUEST[ "JO_account_birth_day" ] ){ 
				$_REQUEST[ "JO_account_birth" ] = $_REQUEST[ "JO_account_birth_year" ] . "-" . $_REQUEST[ "JO_account_birth_month" ] . "-" . $_REQUEST[ "JO_account_birth_day" ];
					}
						$pass_endcode=md5($_REQUEST[ "JO_account_password"	]);
						$query = "
							INSERT INTO `account` (
								`identifier`,
								`password`,
								`name`,
								`mail`,
								`sex`,
								`phone`,
								`address`,
								`birth`,
								`secret_question`,
								`secret_answer`
							) VALUES (
								'" .	$_REQUEST[ "JO_account_identifier"	] . "',
								'" .	$pass_endcode . "',
								'" .	$_REQUEST[ "JO_account_name"		] . "',
								'" .	$_REQUEST[ "JO_account_mail"		] . "',
								" . (	$_REQUEST[ "JO_account_sex"			] ? "'" . $_REQUEST[ "JO_account_sex"		] . "'" : "NULL" ) . ",
								" . (	$_REQUEST[ "JO_account_phone"		] ? "'" . $_REQUEST[ "JO_account_phone"		] . "'" : "NULL" ) . ",
								" . (	$_REQUEST[ "JO_account_address"		] ? "'" . $_REQUEST[ "JO_account_address"	] . "'" : "NULL" ) . ",
								" . (	$_REQUEST[ "JO_account_birth"		] ? "'" . $_REQUEST[ "JO_account_birth"		] . "'" : "NULL" ) . ",
								'" .	$_REQUEST[ "JO_account_quest"		] . "',
								'" .	$_REQUEST[ "JO_account_answer"		] . "'
							)
						";
					}
}
				////
				///
				//	Update
if( $status_name && $status_mail && $status_ans && $status_quest) {
					if( $_REQUEST[ "JO_account_query" ] == "update" ) {
$_REQUEST[ "JO_account_birth" ]='';
					if( $_REQUEST[ "JO_account_birth_year" ] && $_REQUEST[ "JO_account_birth_month" ] && $_REQUEST[ "JO_account_birth_day" ] ){ 
				$_REQUEST[ "JO_account_birth" ] = $_REQUEST[ "JO_account_birth_year" ] . "-" . $_REQUEST[ "JO_account_birth_month" ] . "-" . $_REQUEST[ "JO_account_birth_day" ];}
					$query = "
							UPDATE `account` SET
								`name`			= '" .	$_REQUEST[ "JO_account_name"		] . "',
								`mail`			= '" .	$_REQUEST[ "JO_account_mail"		] . "',
								`sex`			= " . (	$_REQUEST[ "JO_account_sex"			] ? "'" . $_REQUEST[ "JO_account_sex"		] . "'" : "NULL" ) . ",
								`phone`			= " . (	$_REQUEST[ "JO_account_phone"		] ? "'" . $_REQUEST[ "JO_account_phone"		] . "'" : "NULL" ) . ",
								`address`		= " . (	$_REQUEST[ "JO_account_address"		] ? "'" . $_REQUEST[ "JO_account_address"	] . "'" : "NULL" ) . ",
								`birth`			= " . (	$_REQUEST[ "JO_account_birth"		] ? "'" . $_REQUEST[ "JO_account_birth"		] . "'" : "NULL" ) . ",
								`secret_question`			= " . (	$_REQUEST[ "JO_account_quest"		] ? "'" . $_REQUEST[ "JO_account_quest"		] . "'" : "NULL" ) . ",
								`secret_answer`		= " . (	$_REQUEST[ "JO_account_answer"		] ? "'" . $_REQUEST[ "JO_account_answer"		] . "'" : "NULL" ) . "
							WHERE `key` = '" . $_SESSION[ "JO_account_key" ] . "'
						";
						// There are some 'text' type fields.
					}
				if( $_REQUEST[ "JO_account_query" ] == "insert" || $_REQUEST[ "JO_account_query" ] == "update" ) {
					JO_query( $query );
					$_REQUEST[ "JO_head_identifier"	] = $_REQUEST[ "JO_account_identifier"	];
					$_REQUEST[ "JO_head_password"	] = isset($_REQUEST[ "JO_account_password"	])?$_REQUEST[ "JO_account_password"	]:"";
					if( $_REQUEST[ "JO_account_query" ] == "insert" ){ 
						echo "<script> alert( 'Your JukeOn™ account has been created.' ); </script>";
						JO_account_logIn();
					}
					if( $_REQUEST[ "JO_account_query" ] == "update" ) {
						echo "<script> alert( 'Your JukeOn™ account has been updated.' ); </script>";
						JO_account_logIn();
					}
				}
}
		}
		function JO_account_find( ) {	/// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// ///
			foreach( $_REQUEST as $key => $value ) $_REQUEST[ $key ] = trim( $value );
			$query = "
				SELECT	`identifier`, `password`, `name`
				FROM	`account`
				WHERE	`mail` =	'"	. $_REQUEST[ "JO_find_mail" ] . "'
				OR		`mail` LIKE '%"	. $_REQUEST[ "JO_find_mail" ] . "\r\n%'
			";
			$recordSet = JO_query( $query );
			if( empty( $_REQUEST[ "JO_find_mail" ] ) )	{ JO_innerHTM( "JO_find_mail_guide", "The value of 'Mail' is indispensable."							, "JO_absolute JO_negative" ); return false;	}
			else if( $recordSet -> num_rows )			{ JO_innerHTM( "JO_find_mail_guide", "The value of 'Mail' exists in JukeOn™ account database."			, "JO_absolute JO_positive" );					}
			else										{ JO_innerHTM( "JO_find_mail_guide", "The value of 'Mail' does not exist in JukeOn™ account database."	, "JO_absolute JO_negative" ); return false;	}
			if( $_REQUEST[ "JO_find_query" ] == "select" ) {
				while( $record = $recordSet -> fetch_array( ) ) {
					echo $record[ "identifier"	];
					echo $record[ "password"	];
					echo $record[ "name"		];
					// Send a mail.
				}	
				echo "<script> alert( 'Your JukeOn™ account information has been sent to your mail.' ); </script>";
			}
		} function JO_find( ) { return JO_account_find( ); }
    	function JO_account_logIn( ) 
        {
            if(!isset($_SESSION['JO_account_key'])){
				if(!isset($_SESSION['error_login']))
                {
				    $_SESSION['error_login']=0;   
				}
                if(isset($_REQUEST[ "JO_head_password"	]) && $_REQUEST[ "JO_head_password"	]!="")
				$_REQUEST[ "JO_head_password"	]=md5($_REQUEST[ "JO_head_password"	]);
				else
				$_REQUEST[ "JO_head_password"	]=$_SESSION[ "JO_account_pass"			];
				if(isset($_REQUEST[ "JO_head_identifier"	]) && $_REQUEST[ "JO_head_identifier"	]!="")
				$_REQUEST[ "JO_head_identifier"	]=$_REQUEST[ "JO_head_identifier"	];
				else
				$_REQUEST[ "JO_head_identifier"	]=$_SESSION[ "JO_account_identifier"			];
                $sql="SELECT	*
    					FROM	`account`
    					WHERE	`delete` IS NULL
    					AND		`identifier`	= '" . $_REQUEST[ "JO_head_identifier"	] . "'
    					AND		`password`		= '" . $_REQUEST[ "JO_head_password"	] . "'";
                       
                $rs=JO_query($sql);
                $count=$rs->num_rows;;
                if($count==1)
                {
                    if($_SESSION['error_login']=='' || $_SESSION['error_login']<3 )
                    {
                        
                        login_suucess();
                    }
                    if($_SESSION['error_login']=3 )
                    {
                        if(strcmp($_POST['security_code'],$_SESSION['security_code'])==0)
                        {
                            login_suucess();
                        }
                        else
                        {
                            $_SESSION['captcha']='Captcha không dúng';
                            JO_location('JO_00_integration.php?JO_unit=12_login');
                        }
                    }
                }
                else
                {
                    if($_SESSION['error_login']<3 || $_SESSION['error_login']=='')
                    {
                        $_SESSION['error_login']+=1;
                        echo "<script>alert('Dang Nhap Loi Lan Thu ".$_SESSION['error_login']." ,Xin Thu Lai')</script>";
                        JO_location();
                    }
                    if($_SESSION['error_login']=3)
                    {
                       JO_location('JO_00_integration.php?JO_unit=12_login');
                    }
                }
              }
              else
              {
                echo "<script>alert('Ban Da Dang Nhap')</script>";
                JO_location('JO_00_integration.php');
              }
                    
         }    
                
                
			
		 function JO_logIn( $URL = null ) { JO_account_logIn( $URL ); }
        
        function login_suucess(){
                        
	                   	$query = "
        					SELECT	*
        					FROM	`account`
        					WHERE	`delete` IS NULL
        					AND		`identifier`	= '" . $_REQUEST[ "JO_head_identifier"	] . "'
        					AND		`password`		= '" . $_REQUEST[ "JO_head_password"	] . "'
        				";
                       
        				$recordSet = JO_query( $query );
        				if( $recordSet -> num_rows ) $record = $recordSet -> fetch_array( );
        				$_SESSION[ "JO_account_pass"			] = isset($record[ "password"				])?$record[ "password"				]:NULL;
        				$_SESSION[ "JO_account_key"			] = isset($record[ "key"				])?$record[ "key"				]:NULL;
        				$_SESSION[ "JO_account_identifier"	] = isset($record[ "identifier"			])?$record[ "identifier"			]:NULL;
        				$_SESSION[ "JO_account_authority"	] = isset($record[ "authority"			])?$record[ "authority"			]:NULL;
        				$_SESSION[ "JO_account_name"		] = isset($record[ "name"				])?$record[ "name"				]:NULL;
        				$_SESSION[ "JO_account_mail"		] = isset($record[ "mail"				])?$record[ "mail"				]:NULL;
        				$_SESSION[ "JO_account_phone"		] = isset($record[ "phone"				])?$record[ "phone"				]:NULL;
        				$_SESSION[ "JO_account_address"		] = isset($record[ "address"			])?$record[ "address"			]:NULL;
                        $_SESSION[ "JO_account_organ"		] = isset($record[ "organization"			])?$record[ "organization"			]:NULL;
        				$_SESSION[ "JO_account_image"		] = isset($record[ "image"			])?$record[ "image"			]:"";
        				$_SESSION[ "JO_account_quest"		] = isset($record[ "secret_question"			])?$record[ "secret_question"			]:NULL;
        				if( isset($record[ "organization"		] )) $_SESSION[ "JO_account_organization"	] = $record[ "organization"		];
        				if( isset($record[ "language"			] )) $_SESSION[ "JO_account_language"		] = $record[ "language"			];
        			////
        			///
        			//	Point
        				$query = "
        					SELECT	SUM( `point` ) AS `point`
        					FROM	`point`
        					WHERE	`delete` IS NULL
        					AND		`account` = '" . $_SESSION[ "JO_account_key" ] . "'
        				";
        				$recordSet = JO_query( $query );
        				if( $recordSet -> num_rows ) $record = $recordSet -> fetch_array( );
        				$_SESSION[ "JO_account_point" ] = $record[ "point" ];
        			////
        			///
        			//	Favorite
        				JO_favorite_session( );
                        if($_SESSION['error_login']<3){
                            echo "<script>alert('".$_SESSION['error_login']."')</script>";
                        JO_location( $_REQUEST[ "JO_account_return" ] ? urldecode( $_REQUEST[ "JO_account_return" ] ) : null );}
                        if($_SESSION['error_login']=3){
                        
                        JO_location('JO_00_integration.php');}
                        $_SESSION['error_login']=0;
			              
}
		function JO_account_logOut( ) {	/// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// ///
			session_destroy( );
			JO_location( );
		} function JO_logOut( ) { JO_account_logOut( ); }
		function JO_account_authority( $authority = null ) {	/// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// ///
			if( empty( $_SESSION[ "JO_account_authority" ] ) ) exit( "<script> alert( 'You need to log in to use the function.' ); location.replace ( '?JO_unit=11_account&JO_account_return=" . urlencode( $_SERVER[ "REQUEST_URI" ] ) . "' ); </script>" );
			if( $authority && strpos( $_SESSION[ "JO_account_authority" ], $authority ) === false ) exit( "<script> alert( 'Your authority is not enough to use the function.' ); history.back( ); </script>" );
		}
	////
	///
	//	Favorite
		function JO_favorite_insert( ) {	/// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// ///
			if(
				empty( $_REQUEST[ "JO_favorite_subject"	] ) ||
				empty( $_REQUEST[ "JO_favorite_type"	] )
			) {
				echo "<script> alert( '" . JO( array(
					"EN" => "Please input a value to every blank.",
					"KO" => "모든 공란에 값을 입력하십시오.",
					"VI" => "Xin vui lòng nhập vào một giá trị cho mỗi trống."
				) ) . "' ); </script>";
				if(			empty( $_REQUEST[ "JO_favorite_subject"	] ) ) echo "<script> parent.document.getElementById( 'JO_favorite_subject'	).focus( );</script>";
				else if(	empty( $_REQUEST[ "JO_favorite_type"	] ) ) echo "<script> parent.document.getElementById( 'JO_favorite_type'		).focus( );</script>";
				return false;
			}
			global $JO_MySQL;
			$query = "
				UPDATE	`favorite`
				SET		`priority` = `priority` + 1
				WHERE	`delete` IS NULL
				AND		`account` = '" . $_SESSION[ "JO_account_key" ] . "'
			";
			JO_query( $query );
			echo $query = "
				INSERT INTO `favorite` (
					`account`,
					`subject`,
					`type`,
					" . ( $_REQUEST[ "JO_favorite_foreign" ] ? "`foreign`,": "" ) . "
					`log`,
					`insert`
				) VALUES (
					'" . $_SESSION[ "JO_account_key"		] . "',
					'" . $_REQUEST[ "JO_favorite_subject"	] . "',
					'" . $_REQUEST[ "JO_favorite_type"		] . "',
					" . ( $_REQUEST[ "JO_favorite_foreign" ] ? "'" . $_REQUEST[ "JO_favorite_foreign" ] . "\r\n',": "" ) . "
					CONCAT( NOW( ), ' " . $_SESSION[ "JO_account_key" ] . "\r\n' ),
					NOW( )
				)
			";
			JO_query( $query );
			JO_favorite_session( );
			JO_location( );
		}
		function JO_favorite_update( ) {	/// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// ///
			////
			///
			//	Move
				if( $_REQUEST[ "JO_favorite_move" ] && empty( $_REQUEST[ "JO_favorite_foreign" ] ) ) {
					global $JO_MySQL;
					$query = "
						SELECT	`priority`
						FROM	`favorite`
						WHERE	`key`= '" . $_REQUEST[ "JO_favorite_key" ] . "'
					";
					$recordSet = JO_query( $query );
					if( $recordSet -> num_rows ) $record = $recordSet -> fetch_array( ); else return false;
					switch( $_REQUEST[ "JO_favorite_move" ] ) {
						case "top"		: $priority = 127;									break;
						case "up"		: $priority = intval( $record[ "priority" ] ) + 1;	break;
						case "down"		: $priority = intval( $record[ "priority" ] ) - 1;	break;
						case "bottom"	: $priority = -1;									break;
					}
					$query = "
						UPDATE	`favorite`
						SET		`priority`	= '" . $record[ "priority"	] . "'
						WHERE	`delete` IS NULL
						AND		`priority`	= '" . $priority . "'
					";
					JO_query( $query );
					$query = "
						UPDATE	`favorite`
						SET		`priority`	= '" . $priority . "'
						WHERE	`key`		= '" . $_REQUEST[ "JO_favorite_key" ] . "'
					";
					JO_query( $query );
					JO_favorite_priority( );
					JO_location( );
				} else if( $_REQUEST[ "JO_favorite_move" ] && $_REQUEST[ "JO_favorite_foreign" ] ) {
					global $JO_MySQL;
					$query = "
						SELECT	`foreign`
						FROM	`favorite`
						WHERE	`key`= '" . $_REQUEST[ "JO_favorite_key" ] . "'
					";
					$recordSet = JO_query( $query );
					if( $recordSet -> num_rows ) $record = $recordSet -> fetch_array( ); else return false;
					$temp_array = explode( "\r\n", $record[ "foreign" ] );
					$priority_from = array_search( $_REQUEST[ "JO_favorite_foreign" ], $temp_array );
					switch( $_REQUEST[ "JO_favorite_move" ] ) {
						case "top"		: $priority_to = 0;							break;
						case "up"		: $priority_to = $priority_from - 1;		break;
						case "down"		: $priority_to = $priority_from + 1;		break;
						case "bottom"	: $priority_to = count( $temp_array ) - 1;	break;
					}
					$temp_array[ $priority_from	] = $temp_array[ $priority_to ];
					$temp_array[ $priority_to	] = $_REQUEST[ "JO_favorite_foreign" ];
					$foreign = "";
					foreach( $temp_array as $value ) if( $value ) $foreign .= $value . "\r\n";
					$query = "
						UPDATE	`favorite`
						SET		`foreign`	= '" . $foreign							. "'
						WHERE	`key`		= '" . $_REQUEST[ "JO_favorite_key" ]	. "'
					";
					JO_query( $query );
					JO_location( );
			////
			///
			//	Public
				} else if( $_REQUEST[ "JO_favorite_public" ] ) {
					global $JO_MySQL;
					$query = "
						UPDATE	`favorite`
						SET		`public`	= " . (	$_REQUEST[ "JO_favorite_public"	] == "true" ? "TRUE" : "FALSE" ) . "
						WHERE	`key`		= '" .	$_REQUEST[ "JO_favorite_key"	] . "'
					";
					JO_query( $query );
					JO_location( );
			////
			///
			//	Foreign
				} else if( $_REQUEST[ "JO_favorite_foreign" ] ) {
					global $JO_MySQL;
					if( empty( $_REQUEST[ "JO_favorite_key" ] ) ) {
						if( substr_count( $_REQUEST[ "JO_favorite_foreign" ], ";" ) ) {
							$_REQUEST[ "JO_favorite_foreign" ] = substr( $_REQUEST[ "JO_favorite_foreign" ], 0, strlen( $_REQUEST[ "JO_favorite_foreign" ] ) - 1 );
							$_REQUEST[ "JO_favorite_foreign" ] = str_replace( ";", "\r\n", $_REQUEST[ "JO_favorite_foreign" ] );
						}
						JO_favorite_insert( );
					} else {
						$duplication = 0;
						foreach( explode( ";", $_REQUEST[ "JO_favorite_foreign" ] ) as $value ) {
							if( empty( $value ) ) continue;
							$query = "
								SELECT	`key`
								FROM	`favorite`
								WHERE	`key`		= '" .	$_REQUEST[ "JO_favorite_key" ] . "'
								AND		`foreign` LIKE '%" . $value . "\r\n%'
							";
							$recordSet = JO_query( $query );
							if( $recordSet -> num_rows && strpos( $_REQUEST[ "JO_favorite_foreign" ], ";" ) === false ) {
								echo "<script> alert( 'The item is in the favorite, already.' ); </script>";
								return false;
							}
							if( $recordSet -> num_rows && strpos( $_REQUEST[ "JO_favorite_foreign" ], ";" ) !== false ) {
								$duplication ++;
							} else {
								$query = "
									UPDATE	`favorite`
									SET		`foreign`	= CONCAT( `foreign`, " . $value . ", '\r\n' )
									WHERE	`key`		= '" .	$_REQUEST[ "JO_favorite_key" ] . "'
								";
								JO_query( $query );
							}
						}
						if( $duplication == substr_count( $_REQUEST[ "JO_favorite_foreign" ], ";" ) ) echo "<script> alert( 'Every item is in the favorite, already.' ); </script>";
						else if( $duplication														) echo "<script> alert( '" . $duplication . " item" . ( $duplication == 1 ? " was" : "s wer" ) . " duplicated.' ); </script>";
					}
			////
			///
			//	Subject
				} else {
					if( empty( $_REQUEST[ "JO_favorite_subject" ] ) ) {
						echo "<script> alert( '" . JO( array(
							"EN" => "Please input a value to every blank.",
							"KO" => "모든 공란에 값을 입력하십시오.",
							"VI" => "Xin vui lòng nhập vào một giá trị cho mỗi trống."
						) ) . "' ); </script>";
						echo "<script> parent.document.getElementById( 'JO_favorite_subject' ).focus( );</script>";
						return false;
					}
					global $JO_MySQL;
					$query = "
						UPDATE	`favorite`
						SET		`subject`	= '" . $_REQUEST[ "JO_favorite_subject" ] . "',
								`update`	= NOW( )
						WHERE	`key`		= '" . $_REQUEST[ "JO_favorite_key"		] . "'
					";
					JO_query( $query );
					JO_location( );
				}
		}
		function JO_favorite_delete( ) {	/// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// ///
			global $JO_MySQL;
			if( empty( $_REQUEST[ "JO_favorite_foreign" ] ) ) {
				foreach( explode( ";", $_REQUEST[ "JO_favorite_key" ] ) as $value ) {
					if( empty( $value ) ) continue;
					$query = "
						UPDATE	`favorite`
						SET		`delete`	= NOW( )
						WHERE	`key`		= '" . trim( $value ) . "'
					";
					JO_query( $query );
				}
				JO_favorite_priority( );
				JO_favorite_session( );
			} else {
				$query = "
					SELECT	`foreign`
					FROM	`favorite`
					WHERE	`key`= '" . $_REQUEST[ "JO_favorite_key" ] . "'
				";
				$recordSet = JO_query( $query );
				if( $recordSet -> num_rows ) $record = $recordSet -> fetch_array( ); else return false;
				$temp_array = explode( "\r\n", $record[ "foreign" ] );
				foreach( explode( ";", $_REQUEST[ "JO_favorite_foreign" ] ) as $value ) $temp_array[ array_search( $value, $temp_array ) ] = "";
				$foreign = "";
				foreach( $temp_array as $value ) if( $value ) $foreign .= $value . "\r\n";
				$query = "
					UPDATE	`favorite`
					SET		`foreign`	= '" . $foreign							. "'
					WHERE	`key`		= '" . $_REQUEST[ "JO_favorite_key" ]	. "'
				";
				JO_query( $query );
							}
		}
		function JO_favorite_priority( ) {	/// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// ///
			global $JO_MySQL;
			$query = "
				SELECT		`key`,
							`priority`
				FROM		`favorite`
				WHERE		`delete` IS NULL
				AND			`account` = '" . $_SESSION[ "JO_account_key" ] . "'
				ORDER BY	`priority` ASC
			";
			$recordSet = JO_query( $query );
			if( $recordSet -> num_rows ) while( $record = $recordSet -> fetch_array( ) ) {
				$query = "
					UPDATE	`favorite`
					SET		`priority` = '" . intval( $count ++ ) . "'
					WHERE	`key` = '" . $record[ "key" ] . "'
				";
				JO_query( $query );
			}
		}
		function JO_favorite_session( ) {
			global $JO_MySQL;
			$query = "
				SELECT	`key`,
						`subject`,
						`type`
				FROM	`favorite`
				WHERE	`delete` IS NULL
				AND		`account` = '" . $_SESSION[ "JO_account_key" ] . "'
			";
			$recordSet = JO_query( $query );
			$_SESSION[ "JO_account_favorite" ] = array( );
			if( $recordSet -> num_rows ) while( $record = $recordSet -> fetch_array( ) ) $_SESSION[ "JO_account_favorite" ][ $record[ "type" ] ][ $record[ "key" ] ] = $record[ "subject" ];
			
		}
		function JO_artist( $artist ) {
			foreach( explode( "\r\n", $artist ) as $value ) $result .= "<a href='?JO_artist=" . substr( $value, 0, strpos( $value, ":" ) ) . "'>" . substr( $value, strpos( $value, ":" ) + 2 ) . "</a><br />";
			return $result;
		}
		function JO_Save_TopArtist(){
                    if(isset ($_REQUEST["artist"])){
                        $stop=array();
                        $stop=explode(";", $_REQUEST["top"]);
                        $ss="";
                        $ntop=1;
                        $s_query = "update `music`,artist set `position`=null where artist.`key`=music.artist and `artist`.`name`='".urldecode($_REQUEST["artist"])."'
                                        ";
						JO_query($s_query);
                        for($i=(sizeof($stop)-1);$i>=0;$i--){
                            if($stop[$i]!=null && $stop[$i]!=""){
                                $s_query = "update `music` set `position`='".$ntop."' where `key`='".$stop[$i]."'
                                ";
                                JO_query($s_query);
                                $ntop++;
                            }
                        }
                        echo "<script>alert('saved')</script>";
                    }
                    JO_location();
                }
                function JO_uploadimg(){
                    if(isset($_REQUEST["chkupload"])){
                        //uploadimg
                        //$numoffile = 5;
                        $file_dir = "JO_83_image_artist/"; // Tên đường dẫn thư mục chứa file upload
                        if ($_POST) {
                            //for ($i=0;$i<$numoffile;$i++) {
                                if (trim($_FILES['myfiles']['name'])!="") {
                                    $requesttime = gmdate("YmdHis", time()+(7*3600));
                                    $newfile = $file_dir.(isset($_REQUEST["artistid"])?($_REQUEST["artistid"]):"000")."_".$requesttime."_".$_FILES['myfiles']['name'];
                                    if(move_uploaded_file($_FILES['myfiles']['tmp_name'], $newfile)){
                                        $s_query = "
                                        insert into artistimg   (`artist`,`image`,`insert`)
                                                    values      (".$_REQUEST["artistid"].",'".$newfile."',now())
                                        ";
                                    JO_query($s_query);
                                    }else{
                                        echo '<script>alert("Error!");</script>';
                                    }
                                }
                            //}
                        }
/*
                        $userfile = $HTTP_POST_FILES['myfiles']['tmp_name'];
                        // $userfile_name is original file name
                        $userfile_name = $HTTP_POST_FILES['myfiles']['name'];
                        // $userfile_size is size in bytes
                        $userfile_size = $HTTP_POST_FILES['myfiles']['size'];
                        // $userfile_type is mime type e.g. image/gif
                        $userfile_type = $HTTP_POST_FILES['myfiles']['type'];
                        // $userfile_error is any error encountered
                        $userfile_error = $HTTP_POST_FILES['myfiles']['error'];
                        // userfile_error was introduced at PHP 4.2.0
                        // use this code with newer versions
                        if ($userfile_error > 0) {
                            switch ($userfile_error){
                                case 1:
                                    echo '<script>alert("File exceeded upload_max_filesize");</script>';
                                    break;
                                case 2:
                                    echo '<script>alert("File exceeded max_file_size");</script>';
                                    break;
                                case 3:
                                    echo '<script>alert("File only partially uploaded");</script>';
                                    break;
                                case 4:
                                    echo '<script>alert("No file uploaded");</script>';
                                    break;
                            }
                        }else{
                            $upfile = 'JO_83_image_artist/'.$userfile_name;
                            if (is_uploaded_file($userfile)){
                                if (!move_uploaded_file($userfile, $upfile)){
                                    echo '<script>alert("Problem: Could not move file to destination directory");</script>';
                                    //ẽit
                                }else{
                                    //upload successfull
                                    echo '<script>alert("OKE");</script>';
                                }
                            } else {
                                echo '<script>alert("Problem: Possible file upload attack. Filename: '.$userfile_name.'");</script>';
                                //ẽit
                            }
                        }
                        */
                    }else{
                        //linkimg
                        $s_query = "
                                    insert into artistimg   (`artist`,`image`,`insert`)
                                                values      (".$_REQUEST["artistid"].",'".$_REQUEST["txtimgupload"]."',now())
                                    ";
                                JO_query($s_query);
                    }
                    JO_location();
                }
                function JO_deleteimg(){
                    if(isset ($_REQUEST["imgid"])){
                        $s_query = "
                                    update artistimg set `delete`=now() where `key`=".$_REQUEST["imgid"]."
                                        ";
                        JO_query($s_query);
                    }
                    JO_location();
                }
                function JO_editartist(){
                    if(isset ($_REQUEST["artistid"])){
                        $dbirth="'".substr($_REQUEST["txtbirth"],6,4)."-".substr($_REQUEST["txtbirth"],0,2)."-".substr($_REQUEST["txtbirth"],3,2)."'";
                        $s_query = "
                                    update artist 
                                    set `name`='".$_REQUEST["txtname"]."',
                                        autonym='".$_REQUEST["txtautonym"]."',
                                        birth=".($_REQUEST["txtbirth"]!=""?$dbirth:"null").",
                                        sex='".$_REQUEST["jo_sex"]."',
                                        nation='".$_REQUEST["cbxnation"]."',
                                        organization='".$_REQUEST["cbxorganization"]."',
                                        content='".$_REQUEST["txtcontent"]."'
                                    where `key`=".$_REQUEST["artistid"]."
                                        ";
                        echo $s_query;
                        JO_query($s_query);
                    }
                    //JO_location();
                }
#################################################################################
$type=isset($_POST['type'])?$_POST['type']:"";
$sub=isset($_POST['subject'])?$_POST['subject']:"";
$des=isset($_POST['description'])?$_POST['description']:"";
$amount=isset($_POST['amount'])?$_POST['amount']:"";
$start=isset($_POST['start_date'])?$_POST['start_date']:"";
$expired=isset($_POST['expired_date'])?$_POST['expired_date']:"";
$note=isset($_POST['note'])?$_POST['note']:"";
$log=isset($_POST['log'])?$_POST['log']:"";
	function JO_update_recommendation()
		{
			$Query=(
			"
				UPDATE `recommendation` SET
					`type`				= " . (	$_POST[ "type"	] ? "'" . $_POST[ "type"	] . "'" : "NULL" ) . ",
					`subject`			= " . (	$_POST[ "subject"	] ? "'" . $_POST[ "subject"	] . "'" : "NULL" ) . ",
					`description`		= " . (	$_POST[ "description"	] ? "'" . $_POST[ "description"	] . "'" : "NULL" ) . ",
					`amount`			= " . (	$_POST[ "amount"	] ? "'" . $_POST[ "amount"	] . "'" : "NULL" ) . ",
					`start_date`		= " . (	$_POST[ "start_date"	] ? "'" . $_POST[ "start_date"	] . "'" : "NULL" ) . ",
					`expired_date`		= " . (	$_POST[ "expired_date"] ? "'" . $_POST[ "expired_date"	] . "'" : "NULL" ) . ",
					`note`				= " . (	$_POST[ "note"] ? "'" . $_POST[ "note"	] . "'" : "NULL" ) . ",
					`log`		= CONCAT( `log`, NOW( ), ' " . $_SESSION[ "JO_account_key" ] . "\r\n' ),
					`delete`	= NULL,
					`update`	= NOW( )
				WHERE `key`		= '" .	$_POST['key'				] . "'		
			");
if(			JO_query( $Query ))
			echo "<script>alert('Sửa Thành Công');</script>";
			else 			echo "<script>alert('Sửa thất bại');</script>";
		}
		  function JO_insert_recommendation()
  	 {
	   $Query=(
			 "INSERT INTO `recommendation` (
			 			`type`,
						`subject` ,
						`description` ,
						`amount` ,
						`start_date` ,
						`expired_date` ,
						`note`,
						`log`,
						`insert`
					) VALUES (
					" . (	$_POST['type'] ? "'" . $_POST['type'] . "'" : "NULL" ) . ",
					" . (	$_POST['subject'] ? "'" . $_POST['subject'] . "'" : "NULL" ) . ",
					" . (	$_POST['description'] ? "'" . $_POST['description'] . "'" : "NULL" ) . ",
					" . (	$_POST['amount'] ? "'" . $_POST['amount'] . "'" : "NULL" ) . ",
					" . (	$_POST['start_date'] ? "'" . $_POST['start_date'] . "'" : "NULL" ) . ",
					" . (	$_POST['expired_date'] ? "'" . $_POST['expired_date'] . "'" : "NULL" ) . ",
					" . (	$_POST['note'] ? "'" . $_POST['note'] . "'" : "NULL" ) . ",
					CONCAT( NOW( ), ' " . $_SESSION[ "JO_account_key" 	] . "\r\n' ),
					NOW( )
					)
				");
			if(			JO_query( $Query )){
			echo "<script>alert('Thêm Thành Công');window.history.go(1);</script>";
			}
			else 			echo "<script>alert('Thêm thất bại');</script>";
   }
   	function JO_delete_recommendation()
		{
			foreach($_POST["chb"]  as $t=>$gt)
 			{
				$day=date('j-m-y,H:m:s ');
	 			$Query=("UPDATE `jo`.`recommendation` SET `delete` = '$day' WHERE `recommendation`.`key` =$gt");
				JO_query( $Query );
		 	}
			JO_location();
		}
		function JO_save_Top(){
			$recommendation=$_POST['recommendation'];
			$start_date=$_POST['start'];
			$expired_date=$_POST['exp'];
			if(isset($_POST['key']))
			{
				foreach($_POST['key'] as $t=>$gt)
				{
					$chuoi.=",".$gt;
				}
				$chuoi=substr($chuoi,1);
				$querycount="SELECT *
	FROM `recommended_list` Where recommendation= $recommendation
	";
				 $recordSetnum = JO_query( $querycount );
				 $num=$recordSetnum->num_rows;
				if($num>0)
				{
				$Query="update recommended_list set `delete` =now(),`update`=NOW() where `key_item` not in($chuoi) and recommendation =$recommendation";
				JO_query($Query);	
				foreach($_POST['key'] as $t=>$gt)
					{
							$t=$t+1;
							$sql="INSERT INTO `jo`.`recommended_list` ( `recommendation`, `key_item`, `position`, `start_date`, `expired_date`,`insert`,`update`) 
							VALUES ('$recommendation', '$gt', '$t', '$start_date', '$expired_date',NOW( ),NOW( )) on DUPLICATE key
	UPDATE `POSITION`=$t , `update`=NOW(),`delete`=NULL" ;
 		    			JO_query($sql);	
					}
				}
				else
				{
					foreach($_POST['key'] as $t=>$gt)
					{
							$t=$t+1;
							$sql="INSERT INTO `jo`.`recommended_list` ( `recommendation`, `key_item`, `position`, `start_date`, `expired_date`,`insert`) 
							VALUES ('$recommendation', '$gt', '$t', '$start_date', '$expired_date',NOW( )) on DUPLICATE key
	UPDATE `POSITION`=$t,`delete`=NULL";
					JO_query($sql);	
					}
				}
				JO_location();
				}
		else
			{
					$Query="update recommended_list set `delete` =now(),`update`=NOW() where  recommendation =$recommendation";
					JO_query($Query);
					JO_location();	
			}
		}
	####################################################SMS_STATIC-Quan#################################################
		function JO_14_count($cmd,$sea,$sea2,$sea3,$sea4){
		$s_SQLCommand = "call JO_14_count('$cmd','$sea','$sea2','$sea3','$sea4');";
		echo $s_SQLCommand;
		exit;
		$rs_result=JO_query( $s_SQLCommand );
		print_r($rs_result);
		return $rs_result;
		}
		function JO_14_count2($cmd,$sea,$sea2,$sea3,$sea4){
		$s_SQLCommand = "call JO_14_01_count('$cmd','$sea','$sea2','$sea3','$sea4');";
		echo $s_SQLCommand;
		$rs_result=JO_query( $s_SQLCommand );
		print_r($rs_result);
		return $rs_result;
		}
		function JO_14_search_count($loai,$sea,$sea2){
		$s_SQLCommand = "call JO_14_search_count('$loai','$sea','$sea2');";
		$rs_result=JO_query( $s_SQLCommand );
		return $rs_result;
		}
		function JO_14_search_pagelist($loai,$sea,$vt,$limit,$sea2){
		$s_SQLCommand = "call JO_14_search_pagelist('$loai','$sea',$vt,$limit,'$sea2');";
		$rs_result=JO_query( $s_SQLCommand );
		return $rs_result;
		}
		function JO_14_getday_count($from,$to,$sea2){
		$s_SQLCommand = "call JO_14_getday_count('$from','$to','$sea2');";
		$rs_result=JO_query( $s_SQLCommand );
		return $rs_result;
		}
		function JO_14_getday($from,$to,$vt,$limit,$sea2,$sea3){
		$s_SQLCommand = "call JO_14_getday('$from','$to',$vt,$limit,'$sea2','$sea3');";
		$rs_result=JO_query( $s_SQLCommand );
		return $rs_result;
		}
		//---------------------------------------------------end Quan -------------------------------------------
		###########################################Find pass####################################################
			function JO_check_ID($id){
				$s_SQLCommand ="Select * from account where `identifier`='".$id."'AND `delete` IS NULL";
				$rs_result_id = JO_query($s_SQLCommand);
				return $rs_result_id; 
			}
			function JO_update_pass($id,$pass){
				$s_SQLCommand ="UPDATE `jo`.`account` SET `password` = '".$pass."', `update`=NOW() WHERE `account`.`identifier` ='".$id."'";
				$rs_result_update = JO_query($s_SQLCommand);;
				return $rs_result_update; 
			}
			function smtpmailer($SenderEmail,$id,$new_pas,$text,$body,$guser,$gpass,$gname) {//mail nguoi nhan , tai khoan (ten nguoi nhan) , pass muon gui , tieu de mail , noi dung mail , account gmail, pass gmail , ten nguoi gui
				$mail = new PHPMailer();
				$mail->IsSMTP(); // set mailer to use SMTP
				$mail->Host = "smtp.gmail.com"; // specify main and backup server
				$mail->Port = 465; // set the port to use
				$mail->SMTPAuth = true; // turn on SMTP authentication
				$mail->SMTPSecure = 'ssl';
				$mail->Mailer = "smtp"; 
				$mail->CharSet="utf-8";
				$mail->Username = $guser; // your SMTP username or your gmail username
				$mail->Password = $gpass; // your SMTP password or your gmail password
				$from = $guser; // Reply to this email
				$to=$SenderEmail; // Recipients email ID
				$name=$id; // Recipient's name
				$mail->AddReplyTo($guser, "Trả lời"); 
				$mail->From = $from;
				$mail->FromName = $gname; // Name to indicate where the email came from when the recepient received
				$mail->AddAddress($to,$name);
				$mail->AddReplyTo($from,$gname);
				$mail->WordWrap = 50; // set word wrap
				$mail->IsHTML(true); // send as HTML
				$mail->Subject = $text;
				$mail->Body = $body; //HTML Body
				$mail->AltBody = "Cung cấp mật khẩu mới"; //Text Body
				//$mail->SMTPDebug = 2;
				if(!$mail->Send())
				{
					echo "<h1>Loi khi goi mail: " . $mail->ErrorInfo . '</h1>';
					$_SESSION['msg5']='Gửi Mail Thất Bại , Xin Thử Lại';
				}
				else
				{
					$_SESSION['msg4']='(*)Đã gửi mật khẩu mới vào mail bạn đăng kí';
				}
			}  
			function genRandomString() {
				$length = 8;
				$characters = '0123456789abcdefghijklmnopqrstuvwxyz';
				$string = null;    
				for ($p = 0; $p < $length; $p++) {
					$string .= $characters[mt_rand(0, strlen($characters))];
				}
				return $string;
			}
			###############################################################################################
			function getpass()
			{
				$username=isset($_POST['username'])?$_POST['username']:"";
				$question=isset($_POST['secret_question'])?$_POST['secret_question']:"";
				$answer=isset($_POST['secret_answer'])?$_POST['secret_answer']:"";
				###################################
				if($username!=''){
					$kq_id=JO_check_ID($username);
					if($kq_id->num_rows)
					{
						$guser='tuan@neowiz.vn';
						$gpass='e=mc2@';
						$gname='Chăm Sóc Khách Hàng';
						$text='Cung Cấp Lại Tài Khoản';
						$new_pas=genRandomString();
						$body="<b>Bạn hay 1 người nào khác đã dùng địa chỉ Email này để tìm mật khẩu<br/> Nếu không phải là bạn hay nhanh chóng thay đổi thông tin của mình <br/> Đây là mật khẩu tạm thời tốt nhất bạn nên đổi mật khẩu<br/> Mật khẩu Mới : ".$new_pas."</b>";
						$result=$kq_id->fetch_array();
						if($question!="" && $answer!="")
						{
							if(strcmp($question,$result['secret_question'])==0 && strcmp($answer,$result['secret_answer'])==0)
							{
								smtpmailer($result['mail'],$username,$new_pas,$text,$body,$guser,$gpass,$gname);
								JO_update_pass($username,md5($new_pas));
								JO_location();
							}
								else{
							$_SESSION['msg2']='(*)Vui Lòng Kiểm Tra Chính Xác Câu Hỏi Bí Mật Và Câu Trả Lời Để Lấy Lại Mât Khẩu';
							JO_location();
							}
						}
						else{
							$_SESSION['msg2']='(*)Vui Lòng Kiểm Tra Điền Đầy Đủ Câu Hỏi Bí Mật Và Câu Trả Lời Để Lấy Lại Mât Khẩu';
						JO_location();
							}
					}
					else{
						$_SESSION['msg3']='(*)Tài Khoản Không Tồn Tại';
					JO_location();
					}
				 }
			}
		#########################################################################################################
		#######################################change pass ######################################################
		function JO_get_acount($id){
			$s_SQLCommand ="Select * from account where `key`='".$id."'AND `delete` IS NULL";
			$rs_result_id = JO_query($s_SQLCommand);
			return $rs_result_id; 
		}
		function JO_change_pass()
		{
			$id=isset($_POST['txt_id'])?$_POST['txt_id']:"";	
			$pass_old=isset($_POST['txt_pass_old'])?$_POST['txt_pass_old']:"";
			$pass_new=isset($_POST['txt_pass_new'])?$_POST['txt_pass_new']:"";	
			$pass_new_a=isset($_POST['txt_pass_new_a'])?$_POST['txt_pass_new_a']:"";
			$quest=isset($_POST['secret_question'])?$_POST['secret_question']:"";
			$ans=isset($_POST['secret_answer'])?$_POST['secret_answer']:"";
			#####################################################
			if($id!=''){
				$kq_id=JO_check_ID($id);
				if($kq_id->num_rows)
				{
					$guser='tuan@neowiz.vn';
					$gpass='e=mc2@';
					$gname='Chăm Sóc Khách Hàng';
					$text='Thông Báo Đổi Mật Khẩu';
					$body="<b>Bạn vừa thay đổi mật khẩu trên <a href='www.Jukeon.vn'>www.Jukeon.vn</a><br/> Nếu không phải là bạn hay nhanh chóng thay đổi thông tin của mình <br/>Mật khẩu Mới : ".$pass_new."</b>";
					$result=$kq_id->fetch_array();	
					if(strcmp(md5($pass_old),$result['password'])==0)
					{
						if($pass_new!='' && $pass_new_a!=''){
							if(strcmp($pass_new,$pass_new_a)==0)
							{
								if(strcmp($quest,$result['secret_question'])==0 && strcmp($ans,$result['secret_answer'])==0)
								{
									JO_update_pass($id,md5($pass_new));
									smtpmailer($result['mail'],$id,$pass_new,$text,$body,$guser,$gpass,$gname);
									$_SESSION['error_change7']="(*)Đổi Mật Khẩu Thành Công, mật khẩu mới đã được gửi vào mail của bản bạn ";	
									JO_location();
								}
								else{
									$_SESSION['error_change6']="(*)Vui Lòng Kiểm Tra Lại Câu Hỏi Bí Mật Và Câu Trả Lời";	
									$_SESSION['loi']=1;
									JO_location();
								}
							}
							else{
								$_SESSION['error_change5']="(*)Mật Khẩu Mới Không Giống Mật Khẩu Đánh Lại";	
								$_SESSION['loi']=1;
								JO_location();
							}
						}
						else{
								$_SESSION['error_change4']="(*)Vui Lòng Nhập Mật Khẩu Mới";	
								$_SESSION['loi']=1;
								JO_location();
							}	
					}
					else{
					$_SESSION['error_change3']="(*)Mật Khẩu Cũ Không Đúng";	
					$_SESSION['loi']=1;
					JO_location();
					}
				}
				else{
				$_SESSION['error_change3']="(*)Tài Khoản Không Tồn Tại";	
				$_SESSION['loi']=1;
				JO_location();
				}
			}
			else
			{
				$_SESSION['error_change8']="(*)Vui Lòng Nhập Tài Khoản";
				$_SESSION['loi']=1;
				JO_location();
			}
		}
		########################################## upanh avarta #########################################################
			function JO_UpAvarta(){
			if(isset($_REQUEST[ "imgaccount"	]))
					{
						$current=getdate();
						$current=$current['hours'].$current['minutes'].$current['seconds'];
						if($_REQUEST[ "imgaccount"	]!=''){
						$image="image_account/avarta_".$_SESSION['JO_account_identifier'].".jpg";
						$image_up="image_account/avarta_".$_SESSION['JO_account_identifier']."_".time().".jpg";
						}
							else
							$image_up=$_SESSION[ "JO_account_image"		];
					}
					$query = "
							UPDATE `account` SET
								`image`			= '" .	$image_up . "'
							WHERE `key` = '" . $_SESSION[ "JO_account_key" ] . "'
						";
						JO_query($query);
						// There are some 'text' type fields.
						if(isset($_REQUEST[ "imgaccount"	]))
						{
							if($_REQUEST[ "imgaccount"	])
							{
								if(file_exists($image))
								copy($image,$image_up);
								if(file_exists($_SESSION[ "JO_account_image"		]))
								unlink($_SESSION[ "JO_account_image"		]);
								if(file_exists($image))
								unlink($image);
							}
						}
						JO_account_logIn();
			}
		###############################organzination#######################
		function update_organzination()
		{
			$current=getdate();
			$log		 =isset($_POST['log'])	   ?($_POST['log']=="")		?"":$_POST['log']:"";
			$log_n=$current['year']."-".$current['mon']."-".$current['mday']."_".$current['hours']."-".$current['minutes']."-".$current['seconds']."-".$_SESSION['JO_account_identifier'];
			$id=isset($_POST['id'])?$_POST['id']:NULL;
			$name=isset($_POST['name'])?$_POST['name']:NULL;
			$address=isset($_POST['address'])?$_POST['address']:NULL;
			$parent=isset($_POST['parent'])?$_POST['parent']:NULL;
			$prio=isset($_POST['prio'])?$_POST['prio']:NULL;
			$account=isset($_POST['account'])?$_POST['account']:NULL;
			$type=isset($_POST['type'])?$_POST['type']:NULL;
			$phone=isset($_POST['phone'])?$_POST['phone']:NULL;
			$nation=isset($_POST['nation'])?$_POST['nation']:NULL;
			$des=isset($_POST['des'])?$_POST['des']:NULL;
			$note=isset($_POST['note'])?$_POST['note']:NULL;
			$sql='update `organization` set
			     `name`			 ="'.$name	.'",
				`address`			 ="'.$address.'",
				`parent`	     ="'.$parent	.'",
				`priority`	     ="'.$prio	.'",
				`account`		 ="'.$account.'",
				`type`			 ="'.$type	.'",
				`phone`			 ="'.$phone	.'",
				`nation`		 ="'.$nation	.'",
				`description`	 ="'.$des	.'",
				`note`			 ="'.$note	.'" ,
				`log`			 	 = "'.$log.'\r\n'.$log_n.'",
				`update`		 =NOW()
				where `key`    	 ="'.$id  	.'"
			';
			JO_query($sql);
			JO_location();
		}
		function insert_organzination()
		{
			$id		=isset($_POST['id'])	 	 	?($_POST['id']=="")				?"NULL":'"'.$_POST['id'].'"'		:"NULL";
			$name	=isset($_POST['name'])	 	    ?($_POST['name']=="")			?"NULL":'"'.$_POST['name'].'"'		:"NULL";
			$address=isset($_POST['address'])  		?($_POST['address']=="")		?"NULL":'"'.$_POST['address'].'"'	:"NULL";
			$parent	=isset($_POST['parent'])	   	?($_POST['parent']=="")			?"NULL":'"'.$_POST['parent'].'"'	:"NULL";
			$prio	=isset($_POST['priority'])      ?($_POST['priority']=="")		?"0":'"'.$_POST['priority'].'"'	:"0";
			$account=isset($_POST['account'])       ?($_POST['account']=="")		?"NULL":'"'.$_POST['account'].'"'	:"NULL";
			$type	=isset($_POST['type'])	 	    ?($_POST['type']=="")			?"NULL":'"'.$_POST['type'].'"'		:"NULL";
			$phone	=isset($_POST['phone']) 	    ?($_POST['phone']=="")			?"NULL":'"'.$_POST['phone'].'"'		:"NULL";
			$nation	=isset($_POST['nation'])	    ?($_POST['nation']=="")			?"'VN'":'"'.$_POST['nation'].'"'	:"NULL";
			$des	=isset($_POST['des'])	 	    ?($_POST['des']=="")			?"NULL":'"'.$_POST['des'].'"'		:"NULL";
			$note	=isset($_POST['id'])	 	    ?($_POST['note']=="")			?"NULL":'"'.$_POST['note'].'"'		:"NULL";
			$sql="INSERT INTO `jo`.`organization` (
					`name` ,
					`parent` ,
					`address` ,
					`priority` ,
					`account` ,
					`type` ,
					`phone` ,
					`nation` ,
					`description` ,
					`note` ,
					`insert` 
					)
					VALUES (
					$name,$parent,$address,$prio,$account,$type,$phone,$nation,$des,$note,NOW()
					);
			";
			JO_query($sql);
			JO_location();
		}
	###########################################################
	function update_genre()
		{
			$current=getdate();
			$log		 =isset($_POST['log'])	   ?($_POST['log']=="")		?"":$_POST['log']:"";
			$log_n=$current['year']."-".$current['mon']."-".$current['mday'].$current['hours']."-".$current['minutes']."-".$current['seconds']."-".$_SESSION['JO_account_identifier'];
			$id			 =isset($_POST['id'])	 	   ?($_POST['id']=="")			?"NULL":'"'.$_POST['id'].'"':"NULL";
			$subject	 =isset($_POST['subject'])	   ?($_POST['subject']=="")		?"NULL":'"'.$_POST['subject'].'"':"NULL";
			$key_bugs	 =isset($_POST['key_bugs'])	   ?($_POST['key_bugs']=="")	?"NULL":'"'.$_POST['key_bugs'].'"':"NULL";
			$parent	 	 =isset($_POST['parent'])	   ?($_POST['parent']=="")		?"NULL":'"'.$_POST['parent'].'"':"NULL";
			$subject_I18N=isset($_POST['subject_I18N'])?($_POST['subject_I18N']=="")?"NULL":'"'.$_POST['subject_I18N'].'"':"NULL";
			$content_I18N=isset($_POST['content_I18N'])?($_POST['content_I18N']=="")?"NULL":'"'.$_POST['content_I18N'].'"':"NULL";
			$content	 =isset($_POST['content'])?($_POST['content']=="")?"NULL":'"'.$_POST['content'].'"':"NULL";
			$note		 =isset($_POST['note'])		   ?($_POST['note']=="")		?"NULL":'"'.$_POST['note'].'"':"NULL";
			$sql='update `genre` set
			     `subject`			 ='.$subject		.',
				 `key_bugs`			 ='.$key_bugs		.',
				 `subject_I18N`	     ='.$subject_I18N	.',
				 `parent`	     	 ='.$parent			.',
				 `note`			 	 ='.$note			.',
				 `content_I18N`		 ='.$content_I18N	.',
				 `content`			 ='.$content		.',
				 `log`			 	 = "'.$log.'\r\n'.$log_n.'",
				 `update`		 	 =NOW()
				  where `key`    	 ='.$id  			.'
			';
			JO_query($sql);
			JO_location();
		}
		function insert_genre()
		{
			$id			 =isset($_POST['id'])	 	   ?($_POST['id']=="")			?"NULL":'"'.$_POST['id'].'"':"NULL";
			$subject	 =isset($_POST['subject'])	   ?($_POST['subject']=="")		?"NULL":'"'.$_POST['subject'].'"':"NULL";
			$key_bugs	 =isset($_POST['key_bugs'])	   ?($_POST['key_bugs']=="")	?"NULL":'"'.$_POST['key_bugs'].'"':"NULL";
			$parent	 	 =isset($_POST['parent'])	   ?($_POST['parent']=="")		?"NULL":'"'.$_POST['parent'].'"':"NULL";
			$subject_I18N=isset($_POST['subject_I18N'])?($_POST['subject_I18N']=="")?"NULL":'"'.$_POST['subject_I18N'].'"':"NULL";
			$content_I18N=isset($_POST['content_I18N'])?($_POST['content_I18N']=="")?"NULL":'"'.$_POST['content_I18N'].'"':"NULL";
			$content=isset($_POST['content'])?($_POST['content']=="")?"NULL":'"'.$_POST['content'].'"':"NULL";
			$note		 =isset($_POST['note'])		   ?($_POST['note']=="")		?"NULL":'"'.$_POST['note'].'"':"NULL";
			$sql="INSERT INTO `jo`.`genre` (
					`key_bugs` ,
					`parent` ,
					`subject` ,
					`subject_I18N` ,
					`content` ,
					`content_I18N` ,
					`note` ,
					`insert` 
					)
					VALUES (
					 $key_bugs, $parent, $subject, $subject_I18N, $content, $content_I18N, $note,  NOW()
					);
			";
			JO_query($sql);
			JO_location();
		}
		###############################RBT #########################
		function insert_rbt()
		{
			$id			 =isset($_POST['id'])	 	   ?($_POST['id']=="")			?"NULL":'"'.$_POST['id'].'"':"NULL";
			$music		 =isset($_POST['music'])	   ?($_POST['music']=="")		?"NULL":'"'.$_POST['music'].'"':"NULL";
			$note		 =isset($_POST['note'])?($_POST['note']=="")?"NULL":'"'.$_POST['note'].'"':"NULL";
			$provider		 =isset($_POST['provider'])?($_POST['provider']=="")?"NULL":'"'.$_POST['provider'].'"':"NULL";
			$rbt_vt	 =isset($_POST['txt_vt'])	   ?($_POST['txt_vt']=="")		?"NULL":$_POST['txt_vt']:"NULL";
			$rbt_mb	 =isset($_POST['txt_mb'])	   ?($_POST['txt_mb']=="")		?"NULL":$_POST['txt_mb']:"NULL";
			$rbt_vin =isset($_POST['txt_vin'])	   ?($_POST['txt_vin']=="")		?"NULL":$_POST['txt_vin']:"NULL";
			$rbt_vn	 =isset($_POST['txt_vn'])	   ?($_POST['txt_vn']=="")		?"NULL":$_POST['txt_vn']:"NULL";
			$rbt_sf	 =isset($_POST['txt_sf'])	   ?($_POST['txt_sf']=="")		?"NULL":$_POST['txt_sf']:"NULL";
			$rbt_be	 =isset($_POST['txt_be'])	   ?($_POST['txt_be']=="")		?"NULL":$_POST['txt_be']:"NULL";
			###########
			$sub_sql='';
			if($rbt_vt!='NULL')
			$sub_sql.='('.$music.',"VTL8x88",'.$rbt_vt.','.$note.','.$provider.' ,NOW())';
			//mobi
			if($rbt_mb!='NULL' )
			$sub_sql.='('.$music.',"VMS8x88",'.$rbt_mb.','.$note.','.$provider.' ,NOW())';
			//vina
			if($rbt_vin!='NULL' )
			$sub_sql.='('.$music.',"GPC8x88",'.$rbt_vin.','.$note.','.$provider.', NOW())';
			//vietnam
			if($rbt_vn!='NULL')
			$sub_sql.='('.$music.',"VNM8x88",'.$rbt_vn.','.$note.','.$provider.', NOW())';
			//sfone
			if($rbt_sf!='NULL')
			$sub_sql.='('.$music.',"SFN8x88",'.$rbt_sf.','.$note.','.$provider.' ,NOW())';
			//beeline
			if($rbt_be!='NULL' )
			$sub_sql.='('.$music.',"BEE8x88",'.$rbt_be.','.$note.','.$provider.' ,NOW())';
			$sub_sql=str_replace("NOW())","NOW()),",$sub_sql);
			$sub_sql=substr($sub_sql,0,-1);
			################
			if($rbt_vt!='NULL' || $rbt_mb!='NULL' || $rbt_vin!='NULL' || $rbt_vn!='NULL' || $rbt_sf!='NULL' || $rbt_be!='NULL'){
			$sql="INSERT INTO `jo`.`rbt` (
					`music` ,
					`telco` ,
					`rbtcode` ,
					`note` ,
					`provider` ,
					`insert` 
					)
					VALUES ".$sub_sql.
			";";
			JO_query($sql);
			JO_location();
			}
			if($rbt_vt=='NULL' && $rbt_mb=='NULL' && $rbt_vin=='NULL' && $rbt_vn=='NULL' && $rbt_sf=='NULL' && $rbt_be=='NULL')
			{
				echo '<script>alert("cần phải nhập RBT code cho 1 telco");</script>';
				JO_location();	
			}
		}
		###############
		function update_rbt()
		{
			$current=getdate();
			$id			 =isset($_POST['id'])	 	   ?($_POST['id']=="")			?"NULL":'"'.$_POST['id'].'"':"NULL";
			$music		 =isset($_POST['music'])	   ?($_POST['music']=="")		?"NULL":'"'.$_POST['music'].'"':"NULL";
			$log		 =isset($_POST['log'])	   ?($_POST['log']=="")		?"":$_POST['log']:"";
			$log_n=$current['year']."-".$current['mon']."-".$current['mday'].$current['hours']."-".$current['minutes']."-".$current['seconds']."-".$_SESSION['JO_account_identifier'];
			$telco	 	 =isset($_POST['telco'])	   ?($_POST['telco']=="")	?"NULL":'"'.$_POST['telco'].'"':"NULL";
			$rbtcode	 =isset($_POST['rbtcode'])	   ?($_POST['rbtcode']=="")		?"NULL":'"'.$_POST['rbtcode'].'"':"NULL";
			$note		 =isset($_POST['note'])?($_POST['note']=="")?"NULL":'"'.$_POST['note'].'"':"NULL";
			$sql='update `rbt` set
			     `music`			 ='.$music		.',
				 `telco`			 ='.$telco		.',
				 `rbtcode`	     	 ='.$rbtcode	.',
				 `note`			 	 ='.$note		.',
				 `log`			 	 = "'.$log.'\r\n'.$log_n.'",
				 `update`		 	 =NOW()
				  where `key`    	 ='.$id  			.'
			';
			JO_query($sql);
			JO_location();
		}
        /////////////////////////////
        function update_contract(){
        $current=getdate();
	   $id=isset($_POST['id'])?$_POST['id']:"";
        $type		 =isset($_POST['Type'])?'"'.$_POST['Type'].'"':"NULL";
        $subject		 =isset($_POST['subject'])?'"'.$_POST['subject'].'"':"NULL";
        $file		 =isset($_POST['file'])?'"'.$_POST['file'].'"':"NULL";
        $organization		 =isset($_POST['organization'])?'"'.$_POST['organization'].'"':"NULL";
        $note		 =isset($_POST['note'])?'"'.$_POST['note'].'"':"NULL";
        $log		 =isset($_POST['log'])	   ?($_POST['log']=="")		?"":$_POST['log']:"";
		$log_n=$current['year']."-".$current['mon']."-".$current['mday'].$current['hours']."-".$current['minutes']."-".$current['seconds']."-".$_SESSION['JO_account_identifier'];
		if($_FILES['file']['name']!=''){
        $sql='update `contract` set 
              `type`    ='.$type.',
              `subject` ='.$subject.',
              `organization`    ='.$organization.',
              `file`    ="'.$_FILES['file']['name'].'",
              `note`    ='.$note.',
              `log`		="'.$log.'\r\n'.$log_n.'",
              `update`  =Now()
               where
              `key`     ='.$id.'
        ';
		}
		else{
			 $sql='update `contract` set 
              `type`    ='.$type.',
              `subject` ='.$subject.',
              `organization`    ='.$organization.',
              `note`    ='.$note.',
              `log`		="'.$log.'\r\n'.$log_n.'",
              `update`  =Now()
               where
              `key`     ='.$id.'
        ';
		}
        $rs=JO_query($sql);
			if($type=='"Contract"'){
			$dic='JO_72_CO/CO_81_file_contract/'.$_FILES['file']['name'];	}
			if($type=='"settllement"'){
			$dic='JO_72_CO/CO_82_file_settlement/'.$_FILES['file']['name'];	}
			if($type=='"attornment"'){
			$dic='JO_72_CO/CO_83_file_attornment/'.$_FILES['file']['name'];	}
        move_uploaded_file($_FILES['file']['tmp_name'],$dic);
        echo '<script>alert("update success")</script>';
    	JO_location();
}
        function insert_contract(){
	    $id=isset($_POST['id'])?$_POST['id']:"";
        $type		 =isset($_POST['Type'])?'"'.$_POST['Type'].'"':"NULL";
        $subject		 =isset($_POST['subject'])?'"'.$_POST['subject'].'"':"NULL";
        $file		 =isset($_POST['file'])?'"'.$_POST['file'].'"':"NULL";
        $organization		 =isset($_POST['organization'])?'"'.$_POST['organization'].'"':"NULL";
        $note		 =isset($_POST['note'])?'"'.$_POST['note'].'"':"NULL";
        $sql='INSERT INTO `jo`.`contract` (
					`type` ,
					`subject` ,
					`organization` ,
					`file` ,
					`note` ,
					`insert` 
					) values( '.$type.','.$subject.','.$organization.',"'.$_FILES['file']['name'].'",'.$note.',NOW())
        ';
		JO_query($sql);
		$dic='';
			if($type=='"Contract"')
			$dic='JO_72_CO/CO_81_file_contract/'.$_FILES['file']['name'];	
			if($type=='"settlement"')
			$dic='JO_72_CO/CO_82_file_settlement/'.$_FILES['file']['name'];	
			if($type=='"attornment"')
			$dic='JO_72_CO/CO_83_file_attornment/'.$_FILES['file']['name'];	
        move_uploaded_file($_FILES['file']['tmp_name'],$dic);
        echo '<script>alert("insert success")</script>';
   		JO_location();
}
/////////////////////
       function insert_point(){
       $account =isset($_POST['account' ])?$_POST['account' ]:'';
       $point   =isset($_POST['point'   ])?$_POST['point'   ]:'0';
       $free    =isset($_POST['free'    ])?$_POST['free'    ]:'0';
       $subject =isset($_POST['subject' ])?$_POST['subject' ]:'';
       $content =isset($_POST['content' ])?$_POST['content' ]:'';
       $type    =isset($_POST['Type'    ])?$_POST['Type'    ]:'';
       $foreign =isset($_POST['foreign' ])?$_POST['foreign' ]:'';
       $start   =isset($_POST['start'   ])?$_POST['start'   ]:'';
       $end     =isset($_POST['end'     ])?$_POST['end'     ]:'';
       $note    =isset($_POST['note'    ])?$_POST['note'    ]:'';
       $sql='
       INSERT INTO jo.point (`point`,`free`,`subject`,`account`,`content`,`type`,`foreign`,`start`,`end`,`note`,`insert`) VALUES("'.$point.'","'.$free.'","'.$subject.'","'.$account.'","'.$content.'","'.$type.'","'.$foreign.'","'.$start.'","'.$end.'","'.$note.'",NOW())
       ';
       JO_query($sql);
       JO_location();
}  
        function update_point(){
       $current=getdate();
       $id      =isset($_POST['id'      ])?$_POST['id'      ]:'';
       $account =isset($_POST['account' ])?$_POST['account' ]:'';
       $point   =isset($_POST['point'   ])?$_POST['point'   ]:'0';
       $free    =isset($_POST['free'    ])?$_POST['free'    ]:'0';
       $subject =isset($_POST['subject' ])?$_POST['subject' ]:'';
       $content =isset($_POST['content' ])?$_POST['content' ]:'';
       $type    =isset($_POST['Type'    ])?$_POST['Type'    ]:'';
       $foreign =isset($_POST['foreign' ])?$_POST['foreign' ]:'';
       $start   =isset($_POST['start'   ])?$_POST['start'   ]:'';
       $end     =isset($_POST['end'     ])?$_POST['end'     ]:'';
       $note    =isset($_POST['note'    ])?$_POST['note'    ]:'';
        $log		 =isset($_POST['log'])	   ?($_POST['log']=="")		?"":$_POST['log']:"";
		$log_n=$current['year']."-".$current['mon']."-".$current['mday'].$current['hours']."-".$current['minutes']."-".$current['seconds']."-".$_SESSION['JO_account_identifier'];
       $sql='
       update jo.point
       set `account`="'.$account    .'",
           `point`  ="'.$point      .'",
           `free`   ="'.$free       .'",
           `subject`="'.$subject   .'",
           `content`="'.$content    .'",
           `type`   ="'.$type       .'",
           `foreign`="'.$foreign    .'",
           `start`  ="'.$start      .'",
           `end`    ="'.$end        .'",
           `note`   ="'.$note       .'",
           `update` =NOW()             ,
            `log`    ="'.$log.'\r\n'.$log_n.'"
            where `key`="'.$id.'"
       ';
       echo $sql;
       JO_query($sql);
      JO_location();
}  
?>